package com.yy.controller;

import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.yy.model.SysUserEntity;
import com.yy.service.SysUserRoleService;
import com.yy.shiro.ShiroUtils;
import com.yy.view.freemarker.FreeMarkerUtil;

/**
 * Controller公共组件
 * 
 * @author 
 * @date 
 */
public abstract class AbstractController {
	@Autowired
	private SysUserRoleService sysUserRoleService;
	
	protected Logger logger = LoggerFactory.getLogger(getClass());
	
	protected SysUserEntity getUser() {
		return ShiroUtils.getUserEntity();
	}

	protected Long getUserId() {
		return getUser().getUserId();
	}
	/*
	 * 获取当前用户信息角色列表
	 */
	protected List<Long> roleIdList() {
		return sysUserRoleService.queryRoleIdList(getUserId());
	}
	/*
	 * 当前用户信息角色id return 0 则是多角色用户
	 */
	protected int roleId(){
		if (roleIdList().size()==1){
			return roleIdList().get(0).intValue();
		}
		return 0;
	}
	/**
     * 获取模板内容 
     * @param pageName
     * @param dataModel
     * @return
     */
	protected String getTemplateContent(String pageName,Map<String, Object> dataModel){
		return FreeMarkerUtil.getTemplateContent(pageName, dataModel);
	}
}
